package com.example.demo.config.Exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalDefaultExceptionHandler {
    //拦截异常信息，如果返回的是view，方法的返回值是ModelAndView
    //如果反悔的是String或者Json数据，那么需要在方法上添加@ResponseBody注解
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String defaultExceptionHandler(HttpServletRequest request,Exception e){
        //是返回的String

//        ModelAndView mv = new ModelAndView();
//        mv.setViewName(viewName);

        return "服务器错误！" ;
    }


}
